/*
 * Copyright (C) 2017-2021
 * All rights reserved, Designed By
 * Copyright authorization contact 18814114118
 */
package com.shop.cereshop.business.controller.bond;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.shop.cereshop.business.service.bond.CereShopBondWithdrawalService;
import com.shop.cereshop.business.utils.ContextUtil;
import com.shop.cereshop.commons.constant.CoReturnFormat;
import com.shop.cereshop.commons.domain.bond.CereShopBondWithdrawal;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 店铺保证金提现记录模块
 */
@Slf4j
@RestController
@RequestMapping("/bond/withdrawal")
@Api(value = "店铺保证金提现记录模块", tags = "店铺保证金提现记录模块")
public class CereShopBondWithdrawalController {

    @Autowired
    private CereShopBondWithdrawalService withdrawalService;

    @PostMapping("/withdrawal")
    @ApiOperation(value = "保证金提现接口")
    public Result<Object> withdrawal(HttpServletRequest request) throws CoBusinessException {
        Long shopId = ContextUtil.getShopId();
        if (shopId == null) {
            return Result.failed(CoReturnFormat.USER_NOT_LOGIN);
        }
        return null;
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取保证金提现记录列表接口")
    public Result<List<CereShopBondWithdrawal>> list(@RequestParam(defaultValue = "1") @ApiParam(value = "当前页码", required = true) Integer page,
                                                     @RequestParam(defaultValue = "10") @ApiParam(value = "每页数量", required = true) Integer pageSize) throws CoBusinessException {
        Long shopId = ContextUtil.getShopId();
        if (shopId == null) {
            return Result.unauthorized();
        }
        //设置分页参数
        PageHelper.startPage(page, pageSize);
        LambdaQueryWrapper<CereShopBondWithdrawal> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CereShopBondWithdrawal::getShopId, shopId);
        return Result.success(withdrawalService.list(queryWrapper));
    }

    @GetMapping("/detail")
    @ApiOperation(value = "获取保证金提现记录详情接口")
    public Result<CereShopBondWithdrawal> getById(@ApiParam(value = "提现ID", required = true) @RequestParam("withdrawalId") Long withdrawalId) throws CoBusinessException {
        Long shopId = ContextUtil.getShopId();
        if (shopId == null) {
            return Result.unauthorized();
        }
        return Result.success(withdrawalService.getById(withdrawalId));
    }
}